package com.study.lihan.proxy.jdk;

import com.study.lihan.proxy.UserInterface;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author: lihan
 * @Date : 2021/12/31- 12
 * @DESCRIPTION: com.study.lihan.proxy.jdk
 * @version: 1.0
 */
public class MyInvocationHandlerNopublic implements InvocationHandler{

    private NoPublicInterface userInterface;

    public MyInvocationHandlerNopublic(NoPublicInterface userInterface) {
        this.userInterface = userInterface;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(method.getName().equals("test")){
            System.out.println("jdk执行前");
                Object result = method.invoke(userInterface,args);
            System.out.println("jdk执行后");
            return result;
        }

        return method.invoke(userInterface,args);
    }
}
